import { invoke } from '@tauri-apps/api/core';
import type { Container, Image } from '../types';

export async function listContainers(): Promise<Container[]> {
    try {
        return await invoke('list_containers');
    } catch (error) {
        console.error('Failed to list containers:', error);
        throw error;
    }
}

export async function createContainer(image: string, name?: string): Promise<string> {
    try {
        return await invoke('create_container', { image, name });
    } catch (error) {
        console.error('Failed to create container:', error);
        throw error;
    }
}

export async function removeContainer(name: string): Promise<string> {
    try {
        return await invoke('remove_container', { name });
    } catch (error) {
        console.error('Failed to remove container:', error);
        throw error;
    }
}

export async function startContainer(name: string): Promise<string> {
    try {
        return await invoke('start_container', { name });
    } catch (error) {
        console.error('Failed to start container:', error);
        throw error;
    }
}

export async function stopContainer(name: string): Promise<string> {
    try {
        return await invoke('stop_container', { name });
    } catch (error) {
        console.error('Failed to stop container:', error);
        throw error;
    }
}

export async function enterContainer(name: string): Promise<string> {
    try {
        return await invoke('enter_container', { name });
    } catch (error) {
        console.error('Failed to enter container:', error);
        throw error;
    }
}

export async function searchImages(query: string): Promise<Image[]> {
    try {
        return await invoke('search_images', { query });
    } catch (error) {
        console.error('Failed to search images:', error);
        throw error;
    }
} 